﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TabControlDemo
{
	/// <summary>
	/// MainWindow.xaml 的交互逻辑
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			this.InitializeComponent();

			// 在此点下面插入创建对象所需的代码。
		}

        //关闭选项卡
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            string header = btn.Tag.ToString();
            foreach (TabItem item in MainPanel.Items)
            {
                if (item.Header.ToString() == header)
                {
                    MainPanel.Items.Remove(item);
                    break;
                }
            }
        }
        //打开选项卡
        private void TreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeView trv = sender as TreeView;
            TreeViewItem tempItem = trv.SelectedItem as TreeViewItem;
            string header = tempItem.Header.ToString();
            foreach (TabItem tmpItem in MainPanel.Items)
            {
                if (tmpItem.Header.ToString() == header)
                {
                    MainPanel.SelectedItem = tmpItem;
                    return;
                }
            }
            TabItem temptb = new TabItem();
            temptb.Header = header;
            if (header == "用户管理")
            {
                UCUserManage uc = new UCUserManage();
                temptb.Content = uc;
            }
            else if (header == "部门管理")
            {
                UCUserManage uc = new UCUserManage();
                temptb.Content = uc;
            }
            this.MainPanel.Items.Add(temptb);
            MainPanel.SelectedIndex = MainPanel.Items.Count - 1;
        }
	}
}